Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';

var yesOrNoStore=new Ext.data.Store({ 
	proxy:new Ext.data.HttpProxy({
		url:'showType.do?type=YesNo',
		method:'GET'
	}), 
	reader:new Ext.data.JsonReader({ },[
		{name:'name'}, 
		{name:'code'}
		]) 
,
autoLoad:true
});

//债项详情
var addForm = new Ext.form.FormPanel({ 
id: 'addForm', 
title:'资本测算',
renderTo:"form",
height: 300, 
//样式 
bodyStyle: 'margin:5px;text-align:left;padding:5px 60px;', 
frame: true, 
xtype: 'filedset', 
labelWidth: 130, 
items: 
[ 
{ xtype: 'fieldset', 
title:'经济资本信息', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[

 {
	 columnWidth : .5, // 该列有整行中所占百分比
     layout : "form",
     items : [{
  	   xtype: 'textfield', 
  		id:'debtNo',
  		name: 'debtNo', 
  		fieldLabel: '债项流水号', 
  		readOnly:true,
  		width: 200,
  		hidden:true
}
]
 },

 {
 	layout:"column",
 	items:[{
 		columnWidth : .5, // 该列有整行中所占百分比
 	           layout : "form",
 	           items : [{
 	        	   xtype: 'textfield', 
 	        		id:'debtId',
 	        		name: 'debtId', 
 	        		fieldLabel: '债项编号', 
 	        		readOnly:true,
 	        		width: 200
 	}
 	]},{
 		columnWidth : .5, // 该列有整行中所占百分比
 	           layout : "form",
 	           items : [{
 	        	   xtype: 'textfield', 
 	       		id:'debtSum',
 	       		name: 'debtSum', 
 	       		fieldLabel: '债项金额(元)', 
 	       		readOnly:true,
 	       		width: 200 
 	}
 	]} 
 	]},
 

{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
        	   xtype: 'textfield', 
       		id:'pd',
       		name: 'pd', 
       		fieldLabel: '违约概率PD（%）', 
       		readOnly:true,
       		width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'ead',
	name: 'ead', 
	fieldLabel: '违约风险暴露EAD(元)', 
	readOnly:true,
	width: 200
}
]} 
]},
{
	layout:"column",
	items:[{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   xtype: 'textfield', 
	        	   	id:'lgd',
	        	   	name: 'lgd', 
	        	   	fieldLabel: '违约损失率LGD(%)', 
	        	   	readOnly:true,
	        	   	width: 200
	}
	]},{
		columnWidth : .5, // 该列有整行中所占百分比
	           layout : "form",
	           items : [{
	        	   
	}
	]} 
	]},

		{
			layout:"column",
			items:[{
				columnWidth : .5, // 该列有整行中所占百分比
		           layout : "form",
		           items : [{
		        	   xtype: 'combo',         	
						id : "default",
			            store :yesOrNoStore,
			            fieldLabel: '是否违约客户',
			            valueField : 'code',
			            displayField : 'name',
			            typeAhead : true,
			            width: 200,
			            mode:'remote',  
			            hiddenName:'default',
			            editable: false,
			            triggerAction : 'all',
			            selectOnFocus : true,
			            listeners:{  	        	   
				        	   select : function(combo, record,index){
									if(combo.value == '1') Ext.getCmp('beel').setVisible(true);
									else Ext.getCmp('beel').setVisible(false);
								}
						}
			}
			]},{
				columnWidth : .5, // 该列有整行中所占百分比
			           layout : "form",
			           items : [{
			        	   xtype: 'textfield', 
			        		id:'beel',
			        		name: 'beel', 
			        		fieldLabel: '预期损失率最大估计值BEEL（%）', 
			        		readOnly:false,
			        		width: 200,
			        		hidden:true
			}
			]} 
			]},
] 
}],
buttonAlign:'right',
buttons: 
[  

{ text: '测算', handler: editFunction },
] 
});

//结果表单
resultForm = new Ext.form.FormPanel({ 
id: 'resultForm', 
height: 150,
renderTo:"result",
//样式 
bodyStyle: 'margin:5px;text-align:left;padding:5px 60px;', 
frame: true, 
xtype: 'filedset', 
labelWidth: 130, 
items: 
[ { xtype: 'fieldset', 
title: '计算结果', 
collapsible: true, 
autoHeight: true, 
autoWidth: true, 
items: 
[ 
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'el',
	name: 'el', 
	fieldLabel: '预期损失EL(元)', 
	readOnly:true,
	width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'rwa',
	name: 'rwa', 
	fieldLabel: '风险加权资产RWA(元)', 
	readOnly:true,
	width: 200
}
]} 
]},
{layout:"column",
items:[{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'rc',
	name: 'rc', 
	fieldLabel: '监管资本RC(元)', 
	readOnly:true,
	width: 200
}
]},{
	columnWidth : .5, // 该列有整行中所占百分比
           layout : "form",
           items : [{
xtype: 'textfield', 
	id:'ec',
	name: 'ec', 
	fieldLabel: '经济资本EC(元)', 
	readOnly:true,
	width: 200
}
]} 
]}
] 
}]
,
buttonAlign:'right',
buttons: 
[  
{ text: '保存', handler:saveDebtRating },
{ text: '重新计算', handler:returnDebtRating }
],

});

//表单加载数据
addForm.form.load({  
    waitMsg : '正在加载数据请稍后',
    waitTitle : '提示',
    url : 'riskApp/getDebtEC.do', 
    method:'post',
    success:function(form,action){
		Ext.getCmp("default").setValue(action.result.data.isDefault);
		if(action.result.data.isDefault == '1')Ext.getCmp('beel').setVisible(true);
		else Ext.getCmp('beel').setVisible(false);
    	Ext.getCmp("ead").setValue(action.result.data.ead);
    	Ext.getCmp("el").setValue(action.result.data.el);
		Ext.getCmp("rwa").setValue(action.result.data.rwa);
		Ext.getCmp("rc").setValue(action.result.data.rc);
		Ext.getCmp("ec").setValue(action.result.data.ec);
    },  
    failure:function(form,action){
		//window.location.href="view/obligation/DebtGuaranteeInfo.jsp";
    }  
});

function editFunction(){

	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'riskApp/calculateDebtEC.do', 
			method : 'post', 
			success : function(form, action) {
				Ext.getCmp("el").setValue(action.result.data.el);
	    		Ext.getCmp("rwa").setValue(action.result.data.rwa);
	    		Ext.getCmp("rc").setValue(action.result.data.rc);
	    		Ext.getCmp("ec").setValue(action.result.data.ec);
				
				Ext.Msg.alert('提示', '计算成功！'); 		
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '计算失败！'); 
				
			} 
		}); 
	}
}



function returnDebtRating(){

	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'riskApp/calculateDebtEC.do', 
			method : 'post', 
			success : function(form, action) {
				Ext.getCmp("el").setValue(action.result.data.el);
	    		Ext.getCmp("rwa").setValue(action.result.data.rwa);
	    		Ext.getCmp("rc").setValue(action.result.data.rc);
	    		Ext.getCmp("ec").setValue(action.result.data.ec);
				
				Ext.Msg.alert('提示', '计算成功！'); 		
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '计算失败！'); 
				
			} 
		}); 
	}
}

function saveDebtRating(){

	if(addForm.form.isValid()){
		addForm.form.doAction('submit', { 
			url : 'riskApp/saveDebtEC.do', 
			method : 'post', 
			success : function(form, action) {
				Ext.getCmp("el").setValue(action.result.data.el);
	    		Ext.getCmp("rwa").setValue(action.result.data.rwa);
	    		Ext.getCmp("rc").setValue(action.result.data.rc);
	    		Ext.getCmp("ec").setValue(action.result.data.ec);
				
				Ext.Msg.alert('提示', '保存成功！'); 		
			}, 
			failure : function() { 
				Ext.Msg.alert('提示', '保存失败！'); 
				
			} 
		}); 
	}
}
       
}); 